load("@rules_proto//proto:defs.bzl", "proto_library")
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
load("//build:STRINGER.bzl", "stringer")

go_library(
    name = "kvserver",
    srcs = [
        "addressing.go",
        "app_batch.go",
        "consistency_queue.go",
        "debug_print.go",
        "doc.go",
        "flow_control_integration.go",
        "flow_control_raft.go",
        "flow_control_raft_transport.go",
        "flow_control_replica.go",
        "flow_control_replica_integration.go",
        "flow_control_stores.go",
        "lease_history.go",
        "lease_queue.go",
        "markers.go",
        "merge_queue.go",
        "metric_rules.go",
        "metrics.go",
        "mvcc_gc_queue.go",
        "queue.go",
        "queue_helpers_testutil.go",
        "raft.go",
        "raft_log_queue.go",
        "raft_log_truncator.go",
        "raft_snapshot_queue.go",
        "raft_transport.go",
        "raft_transport_metrics.go",
        "raft_truncator_replica.go",
        "range_log.go",
        "rebalance_objective.go",
        "replica.go",
        "replica_app_batch.go",
        "replica_application_cmd.go",
        "replica_application_cmd_buf.go",
        "replica_application_decoder.go",
        "replica_application_result.go",
        "replica_application_state_machine.go",
        "replica_backpressure.go",
        "replica_batch_updates.go",
        "replica_circuit_breaker.go",
        "replica_closedts.go",
        "replica_command.go",
        "replica_consistency.go",
        "replica_corruption.go",
        "replica_destroy.go",
        "replica_eval_context.go",
        "replica_eval_context_span.go",
        "replica_evaluate.go",
        "replica_follower_read.go",
        "replica_gc_queue.go",
        "replica_gossip.go",
        "replica_init.go",
        "replica_metrics.go",
        "replica_placeholder.go",
        "replica_proposal.go",
        "replica_proposal_buf.go",
        "replica_proposal_quota.go",
        "replica_protected_timestamp.go",
        "replica_raft.go",
        "replica_raft_overload.go",
        "replica_raft_quiesce.go",
        "replica_raftstorage.go",
        "replica_range_lease.go",
        "replica_rangefeed.go",
        "replica_rankings.go",
        "replica_rate_limit.go",
        "replica_read.go",
        "replica_send.go",
        "replica_split_load.go",
        "replica_sst_snapshot_storage.go",
        "replica_store_liveness.go",
        "replica_tscache.go",
        "replica_write.go",
        "replicate_queue.go",
        "scanner.go",
        "scheduler.go",
        "split_delay_helper.go",
        "split_queue.go",
        "split_trigger_helper.go",
        "storage_engine_client.go",
        "store.go",
        "store_create_replica.go",
        "store_gossip.go",
        "store_init.go",
        "store_merge.go",
        "store_raft.go",
        "store_rangefeed.go",
        "store_rebalancer.go",
        "store_remove_replica.go",
        "store_replica_btree.go",
        "store_send.go",
        "store_snapshot.go",
        "store_split.go",
        "stores.go",
        "stores_base.go",
        "stores_server.go",
        "testing_knobs.go",
        "ts_maintenance_queue.go",
        ":gen-refreshraftreason-stringer",  # keep
    ],
    embed = [":kvserver_go_proto"],
    importpath = "github.com/cockroachdb/cockroach/pkg/kv/kvserver",
    visibility = ["//visibility:public"],
    deps = [
        "//pkg/base",
        "//pkg/clusterversion",
        "//pkg/config",
        "//pkg/config/zonepb",
        "//pkg/docs",
        "//pkg/gossip",
        "//pkg/keys",
        "//pkg/kv",
        "//pkg/kv/kvbase",
        "//pkg/kv/kvclient/rangecache",
        "//pkg/kv/kvnemesis/kvnemesisutil",
        "//pkg/kv/kvpb",
        "//pkg/kv/kvserver/abortspan",
        "//pkg/kv/kvserver/allocator",
        "//pkg/kv/kvserver/allocator/allocatorimpl",
        "//pkg/kv/kvserver/allocator/load",
        "//pkg/kv/kvserver/allocator/plan",
        "//pkg/kv/kvserver/allocator/storepool",
        "//pkg/kv/kvserver/apply",
        "//pkg/kv/kvserver/batcheval",
        "//pkg/kv/kvserver/batcheval/result",
        "//pkg/kv/kvserver/benignerror",
        "//pkg/kv/kvserver/closedts",
        "//pkg/kv/kvserver/closedts/sidetransport",
        "//pkg/kv/kvserver/closedts/tracker",
        "//pkg/kv/kvserver/concurrency",
        "//pkg/kv/kvserver/concurrency/lock",
        "//pkg/kv/kvserver/concurrency/poison",
        "//pkg/kv/kvserver/constraint",
        "//pkg/kv/kvserver/gc",
        "//pkg/kv/kvserver/idalloc",
        "//pkg/kv/kvserver/intentresolver",
        "//pkg/kv/kvserver/kvadmission",
        "//pkg/kv/kvserver/kvflowcontrol",
        "//pkg/kv/kvserver/kvflowcontrol/kvflowcontrolpb",
        "//pkg/kv/kvserver/kvflowcontrol/kvflowdispatch",
        "//pkg/kv/kvserver/kvflowcontrol/kvflowhandle",
        "//pkg/kv/kvserver/kvflowcontrol/node_rac2",
        "//pkg/kv/kvserver/kvflowcontrol/replica_rac2",
        "//pkg/kv/kvserver/kvserverbase",
        "//pkg/kv/kvserver/kvserverpb",
        "//pkg/kv/kvserver/kvstorage",
        "//pkg/kv/kvserver/leases",
        "//pkg/kv/kvserver/liveness",
        "//pkg/kv/kvserver/liveness/livenesspb",
        "//pkg/kv/kvserver/load",
        "//pkg/kv/kvserver/lockspanset",
        "//pkg/kv/kvserver/logstore",
        "//pkg/kv/kvserver/multiqueue",
        "//pkg/kv/kvserver/raftentry",
        "//pkg/kv/kvserver/raftlog",
        "//pkg/kv/kvserver/rangefeed",
        "//pkg/kv/kvserver/rditer",
        "//pkg/kv/kvserver/readsummary",
        "//pkg/kv/kvserver/readsummary/rspb",
        "//pkg/kv/kvserver/replicastats",
        "//pkg/kv/kvserver/spanset",
        "//pkg/kv/kvserver/split",
        "//pkg/kv/kvserver/stateloader",
        "//pkg/kv/kvserver/storeliveness",
        "//pkg/kv/kvserver/storeliveness/storelivenesspb",
        "//pkg/kv/kvserver/tenantrate",
        "//pkg/kv/kvserver/tscache",
        "//pkg/kv/kvserver/txnrecovery",
        "//pkg/kv/kvserver/txnwait",
        "//pkg/kv/kvserver/uncertainty",
        "//pkg/multitenant",
        "//pkg/multitenant/tenantcapabilities/tenantcapabilitiesauthorizer",
        "//pkg/multitenant/tenantcostmodel",
        "//pkg/raft",
        "//pkg/raft/raftpb",
        "//pkg/raft/raftstoreliveness",
        "//pkg/raft/tracker",
        "//pkg/roachpb",
        "//pkg/rpc",
        "//pkg/rpc/nodedialer",
        "//pkg/server/status",
        "//pkg/server/telemetry",
        "//pkg/settings",
        "//pkg/settings/cluster",
        "//pkg/spanconfig",
        "//pkg/spanconfig/spanconfigstore",
        "//pkg/storage",
        "//pkg/storage/disk",
        "//pkg/storage/enginepb",
        "//pkg/storage/fs",
        "//pkg/util",
        "//pkg/util/admission",
        "//pkg/util/admission/admissionpb",
        "//pkg/util/buildutil",
        "//pkg/util/circuit",
        "//pkg/util/ctxgroup",
        "//pkg/util/encoding",
        "//pkg/util/envutil",
        "//pkg/util/errorutil",
        "//pkg/util/growstack",
        "//pkg/util/grpcutil",
        "//pkg/util/grunning",
        "//pkg/util/hlc",
        "//pkg/util/humanizeutil",
        "//pkg/util/iterutil",
        "//pkg/util/limit",
        "//pkg/util/log",
        "//pkg/util/log/logcrash",
        "//pkg/util/log/severity",
        "//pkg/util/metamorphic",
        "//pkg/util/metric",
        "//pkg/util/metric/aggmetric",
        "//pkg/util/mon",
        "//pkg/util/pprofutil",
        "//pkg/util/protoutil",
        "//pkg/util/quotapool",
        "//pkg/util/retry",
        "//pkg/util/shuffle",
        "//pkg/util/slidingwindow",
        "//pkg/util/stop",
        "//pkg/util/syncutil",
        "//pkg/util/syncutil/singleflight",
        "//pkg/util/timeutil",
        "//pkg/util/tracing",
        "//pkg/util/tracing/tracingpb",
        "//pkg/util/uuid",
        "@com_github_cockroachdb_errors//:errors",
        "@com_github_cockroachdb_logtags//:logtags",
        "@com_github_cockroachdb_pebble//:pebble",
        "@com_github_cockroachdb_pebble//objstorage",
        "@com_github_cockroachdb_pebble//objstorage/remote",
        "@com_github_cockroachdb_pebble//rangekey",
        "@com_github_cockroachdb_pebble//sstable",
        "@com_github_cockroachdb_pebble//vfs",
        "@com_github_cockroachdb_redact//:redact",
        "@com_github_gogo_protobuf//proto",
        "@com_github_google_btree//:btree",
        "@com_github_kr_pretty//:pretty",
        "@com_github_prometheus_client_golang//prometheus",
        "@com_github_prometheus_client_model//go",
        "@io_opentelemetry_go_otel//attribute",
        "@org_golang_google_grpc//:go_default_library",
        "@org_golang_x_time//rate",
    ],
)

go_test(
    name = "kvserver_test",
    size = "enormous",
    srcs = [
        "addressing_test.go",
        "allocator_impl_test.go",
        "batch_spanset_test.go",
        "below_raft_protos_test.go",
        "client_atomic_membership_change_test.go",
        "client_decommission_test.go",
        "client_invalidsplit_test.go",
        "client_lease_test.go",
        "client_manual_proposal_test.go",
        "client_merge_test.go",
        "client_metrics_test.go",
        "client_migration_test.go",
        "client_mvcc_gc_test.go",
        "client_protectedts_test.go",
        "client_raft_helpers_test.go",
        "client_raft_log_queue_test.go",
        "client_raft_test.go",
        "client_rangefeed_test.go",
        "client_relocate_range_test.go",
        "client_replica_backpressure_test.go",
        "client_replica_circuit_breaker_test.go",
        "client_replica_gc_test.go",
        "client_replica_raft_overload_test.go",
        "client_replica_test.go",
        "client_spanconfigs_test.go",
        "client_split_burst_test.go",
        "client_split_test.go",
        "client_store_test.go",
        "client_tenant_test.go",
        "client_test.go",
        "closed_timestamp_test.go",
        "consistency_queue_test.go",
        "debug_print_test.go",
        "errors_test.go",
        "flow_control_integration_test.go",
        "flow_control_raft_transport_test.go",
        "flow_control_replica_integration_test.go",
        "gossip_test.go",
        "helpers_test.go",
        "intent_resolver_integration_test.go",
        "lease_history_test.go",
        "lease_queue_test.go",
        "main_test.go",
        "merge_queue_test.go",
        "metric_rules_test.go",
        "metrics_test.go",
        "mvcc_gc_queue_test.go",
        "node_liveness_test.go",
        "queue_concurrency_test.go",
        "queue_test.go",
        "raft_log_queue_test.go",
        "raft_log_truncator_test.go",
        "raft_test.go",
        "raft_transport_test.go",
        "raft_transport_unit_test.go",
        "range_log_test.go",
        "rebalance_objective_test.go",
        "replica_application_cmd_buf_test.go",
        "replica_application_result_test.go",
        "replica_application_state_machine_test.go",
        "replica_batch_updates_test.go",
        "replica_circuit_breaker_test.go",
        "replica_closedts_internal_test.go",
        "replica_closedts_test.go",
        "replica_command_test.go",
        "replica_consistency_test.go",
        "replica_evaluate_test.go",
        "replica_follower_read_test.go",
        "replica_gc_queue_test.go",
        "replica_init_test.go",
        "replica_learner_test.go",
        "replica_lease_renewal_test.go",
        "replica_metrics_test.go",
        "replica_probe_test.go",
        "replica_proposal_bench_test.go",
        "replica_proposal_buf_test.go",
        "replica_protected_timestamp_test.go",
        "replica_raft_overload_test.go",
        "replica_raft_test.go",
        "replica_raft_truncation_test.go",
        "replica_rangefeed_test.go",
        "replica_rankings_test.go",
        "replica_sideload_test.go",
        "replica_split_load_test.go",
        "replica_sst_snapshot_storage_test.go",
        "replica_store_liveness_test.go",
        "replica_test.go",
        "replica_tscache_test.go",
        "replicate_queue_test.go",
        "replicate_test.go",
        "reset_quorum_test.go",
        "scanner_test.go",
        "scatter_test.go",
        "scheduler_test.go",
        "single_key_test.go",
        "split_delay_helper_test.go",
        "split_queue_test.go",
        "split_trigger_helper_test.go",
        "stats_test.go",
        "store_gossip_test.go",
        "store_pool_test.go",
        "store_raft_test.go",
        "store_rangefeed_test.go",
        "store_rebalancer_test.go",
        "store_replica_btree_test.go",
        "store_test.go",
        "stores_test.go",
        "testutils_test.go",
        "ts_maintenance_queue_test.go",
        "txn_recovery_integration_test.go",
        "txn_wait_queue_test.go",
    ],
    data = glob(["testdata/**"]),
    embed = [":kvserver"],
    exec_properties = {
        "test.Pool": "heavy",
    },
    shard_count = 48,
    tags = ["cpu:2"],
    deps = [
        "//pkg/base",
        "//pkg/ccl",
        "//pkg/cli/exit",
        "//pkg/cloud",
        "//pkg/cloud/nodelocal",
        "//pkg/clusterversion",
        "//pkg/config",
        "//pkg/config/zonepb",
        "//pkg/gossip",
        "//pkg/jobs",
        "//pkg/jobs/jobspb",
        "//pkg/jobs/jobsprotectedts",
        "//pkg/keys",
        "//pkg/keyvisualizer",
        "//pkg/kv",
        "//pkg/kv/kvclient",
        "//pkg/kv/kvclient/kvcoord",
        "//pkg/kv/kvclient/rangefeed",
        "//pkg/kv/kvclient/rangefeed/rangefeedcache",
        "//pkg/kv/kvpb",
        "//pkg/kv/kvserver/abortspan",
        "//pkg/kv/kvserver/allocator",
        "//pkg/kv/kvserver/allocator/allocatorimpl",
        "//pkg/kv/kvserver/allocator/load",
        "//pkg/kv/kvserver/allocator/plan",
        "//pkg/kv/kvserver/allocator/storepool",
        "//pkg/kv/kvserver/apply",
        "//pkg/kv/kvserver/batcheval",
        "//pkg/kv/kvserver/batcheval/result",
        "//pkg/kv/kvserver/benignerror",
        "//pkg/kv/kvserver/closedts",
        "//pkg/kv/kvserver/closedts/tracker",
        "//pkg/kv/kvserver/concurrency",
        "//pkg/kv/kvserver/concurrency/isolation",
        "//pkg/kv/kvserver/concurrency/lock",
        "//pkg/kv/kvserver/gc",
        "//pkg/kv/kvserver/intentresolver",
        "//pkg/kv/kvserver/kvadmission",
        "//pkg/kv/kvserver/kvflowcontrol",
        "//pkg/kv/kvserver/kvflowcontrol/kvflowcontrolpb",
        "//pkg/kv/kvserver/kvflowcontrol/kvflowdispatch",
        "//pkg/kv/kvserver/kvflowcontrol/kvflowinspectpb",
        "//pkg/kv/kvserver/kvflowcontrol/node_rac2",
        "//pkg/kv/kvserver/kvflowcontrol/replica_rac2",
        "//pkg/kv/kvserver/kvserverbase",
        "//pkg/kv/kvserver/kvserverpb",
        "//pkg/kv/kvserver/kvstorage",
        "//pkg/kv/kvserver/leases",
        "//pkg/kv/kvserver/liveness",
        "//pkg/kv/kvserver/liveness/livenesspb",
        "//pkg/kv/kvserver/load",
        "//pkg/kv/kvserver/lockspanset",
        "//pkg/kv/kvserver/logstore",
        "//pkg/kv/kvserver/protectedts",
        "//pkg/kv/kvserver/protectedts/ptpb",
        "//pkg/kv/kvserver/protectedts/ptstorage",
        "//pkg/kv/kvserver/protectedts/ptutil",
        "//pkg/kv/kvserver/raftentry",
        "//pkg/kv/kvserver/raftlog",
        "//pkg/kv/kvserver/raftutil",
        "//pkg/kv/kvserver/rangefeed",
        "//pkg/kv/kvserver/rditer",
        "//pkg/kv/kvserver/readsummary/rspb",
        "//pkg/kv/kvserver/replicastats",
        "//pkg/kv/kvserver/spanset",
        "//pkg/kv/kvserver/split",
        "//pkg/kv/kvserver/stateloader",
        "//pkg/kv/kvserver/tenantrate",
        "//pkg/kv/kvserver/tscache",
        "//pkg/kv/kvserver/txnwait",
        "//pkg/kv/kvserver/uncertainty",
        "//pkg/multitenant/tenantcapabilities/tenantcapabilitiesauthorizer",
        "//pkg/raft",
        "//pkg/raft/confchange",
        "//pkg/raft/quorum",
        "//pkg/raft/raftpb",
        "//pkg/raft/tracker",
        "//pkg/roachpb",
        "//pkg/rpc",
        "//pkg/rpc/nodedialer",
        "//pkg/security/securityassets",
        "//pkg/security/securitytest",
        "//pkg/security/username",
        "//pkg/server",
        "//pkg/server/serverpb",
        "//pkg/server/telemetry",
        "//pkg/settings",
        "//pkg/settings/cluster",
        "//pkg/spanconfig",
        "//pkg/spanconfig/spanconfigptsreader",
        "//pkg/spanconfig/spanconfigstore",
        "//pkg/spanconfig/spanconfigtestutils",
        "//pkg/sql",
        "//pkg/sql/catalog/bootstrap",
        "//pkg/sql/catalog/catalogkeys",
        "//pkg/sql/catalog/dbdesc",
        "//pkg/sql/catalog/descpb",
        "//pkg/sql/catalog/systemschema",
        "//pkg/sql/gcjob",
        "//pkg/sql/isql",
        "//pkg/sql/rowenc/keyside",
        "//pkg/sql/sem/tree",
        "//pkg/sql/sqlstats",
        "//pkg/storage",
        "//pkg/storage/disk",
        "//pkg/storage/enginepb",
        "//pkg/storage/fs",
        "//pkg/testutils",
        "//pkg/testutils/datapathutils",
        "//pkg/testutils/echotest",
        "//pkg/testutils/gossiputil",
        "//pkg/testutils/jobutils",
        "//pkg/testutils/kvclientutils",
        "//pkg/testutils/listenerutil",
        "//pkg/testutils/serverutils",
        "//pkg/testutils/skip",
        "//pkg/testutils/sqlutils",
        "//pkg/testutils/storageutils",
        "//pkg/testutils/testcluster",
        "//pkg/ts",
        "//pkg/ts/tspb",
        "//pkg/upgrade/upgradebase",
        "//pkg/util",
        "//pkg/util/admission",
        "//pkg/util/admission/admissionpb",
        "//pkg/util/allstacks",
        "//pkg/util/caller",
        "//pkg/util/circuit",
        "//pkg/util/ctxgroup",
        "//pkg/util/encoding",
        "//pkg/util/grunning",
        "//pkg/util/hlc",
        "//pkg/util/humanizeutil",
        "//pkg/util/leaktest",
        "//pkg/util/log",
        "//pkg/util/log/logpb",
        "//pkg/util/metric",
        "//pkg/util/mon",
        "//pkg/util/netutil",
        "//pkg/util/protoutil",
        "//pkg/util/quotapool",
        "//pkg/util/randutil",
        "//pkg/util/rangedesc",
        "//pkg/util/retry",
        "//pkg/util/stop",
        "//pkg/util/syncutil",
        "//pkg/util/timeutil",
        "//pkg/util/tracing",
        "//pkg/util/tracing/tracingpb",
        "//pkg/util/uint128",
        "//pkg/util/uuid",
        "@com_github_cockroachdb_cockroach_go_v2//crdb",
        "@com_github_cockroachdb_datadriven//:datadriven",
        "@com_github_cockroachdb_errors//:errors",
        "@com_github_cockroachdb_errors//oserror",
        "@com_github_cockroachdb_logtags//:logtags",
        "@com_github_cockroachdb_pebble//:pebble",
        "@com_github_cockroachdb_pebble//sstable",
        "@com_github_cockroachdb_pebble//vfs",
        "@com_github_cockroachdb_redact//:redact",
        "@com_github_dustin_go_humanize//:go-humanize",
        "@com_github_gogo_protobuf//proto",
        "@com_github_google_btree//:btree",
        "@com_github_jackc_pgx_v4//:pgx",
        "@com_github_kr_pretty//:pretty",
        "@com_github_lib_pq//:pq",
        "@com_github_olekukonko_tablewriter//:tablewriter",
        "@com_github_prometheus_common//expfmt",
        "@com_github_stretchr_testify//assert",
        "@com_github_stretchr_testify//require",
        "@org_golang_google_grpc//:go_default_library",
        "@org_golang_google_grpc//metadata",
        "@org_golang_x_sync//errgroup",
        "@org_golang_x_sync//syncmap",
        "@org_golang_x_time//rate",
    ],
)

proto_library(
    name = "kvserver_proto",
    srcs = [
        "api.proto",
        "storage_services.proto",
    ],
    strip_import_prefix = "/pkg",
    visibility = ["//visibility:public"],
    deps = [
        "//pkg/kv/kvserver/kvserverpb:kvserverpb_proto",
        "//pkg/roachpb:roachpb_proto",
        "//pkg/storage/enginepb:enginepb_proto",
        "@com_github_gogo_protobuf//gogoproto:gogo_proto",
    ],
)

go_proto_library(
    name = "kvserver_go_proto",
    compilers = ["//pkg/cmd/protoc-gen-gogoroach:protoc-gen-gogoroach_grpc_compiler"],
    importpath = "github.com/cockroachdb/cockroach/pkg/kv/kvserver",
    proto = ":kvserver_proto",
    visibility = ["//visibility:public"],
    deps = [
        "//pkg/kv/kvserver/kvserverpb",
        "//pkg/roachpb",
        "//pkg/storage/enginepb",
        "@com_github_gogo_protobuf//gogoproto",
    ],
)

stringer(
    name = "gen-refreshraftreason-stringer",
    src = "replica_raft.go",
    typ = "refreshRaftReason",
)
